/*
* @file model/pdtFunds.js
*  产品管理/查看资金
* @author
*
*/
import { routerRedux } from 'dva/router';
import api from '../api';

export default {
	namespace:'pdtfunds',
	state:{
		fundslist:[],
		currentpage:1,
		pageSize:15
	},
	subscriptions:{
		setup({dispatch,history}) {
			history.listen(({pathname,query}) => {
				if( pathname === '/systemMgt/accountMgt/pdtMgt/examine'){
					dispatch({
						type: 'getList',
						payload: {
							...query,
						}
					})
				}
			})
		}
	},
	effects:{
		*	getList({payload:query},{call,put}){
			yield put({
				type:'initData',
				payload:{
					fundslist:[],
				}
			})
			const response = yield call(api.getfundsList, query);
				yield put({
					type: 'getListSuccess',
					payload: {
						...response
					},
				});
		},
		*changeState({payload:query},{call,put}){
			// console.log('query------',query)
			yield put({
				type: 'getList',
				payload: {
					...query,
				}
			})
		},
		*fundschangeRoute({payload:query},{call,put}){
			yield put(routerRedux.push({
				pathname:`/systemMgt/accountMgt/pdtMgt/examine`,
				query:{
					...query,
				}
			}))
		}
	},
	reducers:{
		initData(state, {payload}) {
			return {
				...state,
				...payload
			}
		},
		getListSuccess(state, {payload}) {
			const {data,page} = payload
			const status=data ? true:false
			return {
				...state,
				status,
				fundslist:data,
				page,
			}
		},
	}
}
